<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
                    <p:panel>
                        <f:facet name="header" >
                            <h:outputLabel value="SEARCH Bill"/>                          
                            <h:panelGrid columns="2" >



                                <h:outputLabel value="Bill No(Ins ID)"/>
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.insId}" />
                                <h:outputLabel value="Bill No(Dept ID)"/>
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.deptId}" />

                                <h:outputLabel value="BHT No"/>
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.bhtNo}" />
                                
                                <h:outputLabel value="Bill ID"/>
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.refBillNo}" />

                                <p:commandButton id="btnSearch" ajax="false" value="Search" action="#{searchController.createSearchBill()}"/>

                            </h:panelGrid>

                            <p:defaultCommand target="btnSearch" />

                        </f:facet>

                        <p:dataTable rowIndexVar="i" id="tblBills" value="#{searchController.bills}" var="bill"  style="min-width: 100%;"  >
                            <p:column headerText="View" styleClass="alignTop">
                                <p:commandButton value="View Bill" action="bill_all_view" ajax="false">
                                    <f:setPropertyActionListener value="#{bill}" target="#{billSearch.billSearch}" />
                                </p:commandButton>
                            </p:column>
                            
                            <p:column>
                                #{bill.id}
                            </p:column>

                            <p:column headerText="Bill No(Instiution Id)" >                              
                                <h:outputLabel  value="#{bill.insId}" ></h:outputLabel>
                                <br/>
                                <h:panelGroup rendered="#{bill.cancelled}" >
                                    <h:outputLabel style="color: red;" rendered="#{bill.cancelled}" value="#{bill.cancelledBill.insId}" >                                       
                                    </h:outputLabel>
                                </h:panelGroup>
                                <h:panelGroup rendered="#{bill.refunded}" >
                                    <h:outputLabel style="color: red;" rendered="#{bill.refunded}" value="#{bill.refundedBill.insId}" >
                                    </h:outputLabel>
                                </h:panelGroup>
                            </p:column>       
                            <p:column headerText="Bill No(Department Id)" >                              
                                <h:outputLabel  value="#{bill.deptId}" ></h:outputLabel>    
                                <br/>
                                <h:panelGroup rendered="#{bill.cancelled}" >
                                    <h:outputLabel style="color: red;" rendered="#{bill.cancelled}" value="#{bill.cancelledBill.deptId}" >                                       
                                    </h:outputLabel>
                                </h:panelGroup>
                                <h:panelGroup rendered="#{bill.refunded}" >
                                    <h:outputLabel style="color: red;" rendered="#{bill.refunded}" value="#{bill.refundedBill.deptId}" >
                                    </h:outputLabel>
                                </h:panelGroup>
                            </p:column>
                            <p:column headerText="Institution"  >                              
                                <h:outputLabel value="#{bill.institution.name}"  ></h:outputLabel>                                  
                            </p:column>
                            <p:column headerText="Billed at"  >                              
                                <h:outputLabel value="#{bill.createdAt}" >
                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss:SSS a"/>
                                </h:outputLabel>                                    
                                <br/>
                                <h:panelGroup rendered="#{bill.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled at " />
                                    <h:outputLabel style="color: red;" rendered="#{bill.cancelled}" value="#{bill.cancelledBill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss:SSS a"/>
                                    </h:outputLabel>
                                </h:panelGroup>
                                <h:panelGroup rendered="#{bill.refunded}" >
                                    <h:outputLabel style="color: red;" value="Refunded at " />
                                    <h:outputLabel style="color: red;" rendered="#{bill.refunded}" value="#{bill.refundedBill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss:SSS a"/>
                                    </h:outputLabel>
                                </h:panelGroup>
                            </p:column>  
                            <p:column headerText="Billed by" >                              
                                <h:outputLabel value="#{bill.creater.webUserPerson.name}" >                                      
                                </h:outputLabel>                                   
                                <br/>
                                <h:panelGroup rendered="#{bill.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled By " />
                                    <h:outputLabel style="color: red;" rendered="#{bill.cancelled}" value="#{bill.cancelledBill.creater.webUserPerson.name}" >                                       
                                    </h:outputLabel>
                                </h:panelGroup>
                                <h:panelGroup rendered="#{bill.refunded}" >
                                    <h:outputLabel style="color: red;" value="Refunded By " />
                                    <h:outputLabel style="color: red;" rendered="#{bill.refunded}" value="#{bill.refundedBill.creater.webUserPerson.name}" >

                                    </h:outputLabel>
                                </h:panelGroup>
                            </p:column>    
                            <p:column headerText="Payment Method" >                              
                                <h:outputLabel value="#{bill.paymentMethod}" ></h:outputLabel>                                   
                            </p:column>
                            <p:column headerText="Gross Value"  >                              
                                <h:outputLabel value="#{bill.total}" >
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>                                   
                            </p:column>
                            <p:column headerText="Discount" >                             
                                <h:outputLabel value="#{bill.discount}" >
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>                                    
                            </p:column>
                            <p:column headerText="Margin" >                             
                                <h:outputLabel value="#{bill.margin}" >
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>                                    
                            </p:column>
                            <p:column headerText="Net Value" >                                
                                <h:outputLabel value="#{bill.netTotal}" >
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>                                  
                            </p:column>                         
                            <p:column headerText="Comments" >
                                <h:outputLabel rendered="#{bill.refundedBill ne null}" value="#{bill.refundedBill.comments}" >
                                </h:outputLabel>
                                <h:outputLabel  rendered="#{bill.cancelledBill ne null}" value="#{bill.cancelledBill.comments}" >
                                </h:outputLabel>
                            </p:column>
                        </p:dataTable>


                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
